<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
class Customers {
    var $id;
    var $address;
    var $city;
    var $email;
    var $phone;
    var $fax;
    var $company_id;
    var $department_id;


    function open($id){
        global $db;
        $sql="select * from customers where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->address=$address;
            $this->city=$city;
            $this->email=$email;
            $this->phone=$phone;
            $this->fax=$fax;
            $this->company_id=$company_id;
            $this->department_id=$department_id;

        }
    }

    function openAll(){
        $sql="select * from customers order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into customers values (null,'{$this->address}',
'{$this->city}','{$this->email}',
'{$this->phone}','{$this->fax}',
'{$this->company_id}','{$this->department_id}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update customers set address='{$this->address}',
city='{$this->city}',email='{$this->email}',
phone='{$this->phone}',fax='{$this->fax}',
company_id='{$this->company_id}',
department_id='{$this->department_id}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from customers where id=".$this->id;
        $db->query($sql);
    }

}
?>
